﻿using ModelLayer.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace ModelLayer.Graph
{
    [KnownType(typeof(StationNetworkGraph))]
    [DataContract]
    public class StationNode
    {
        [DataMember]
        public int Id { get; set; }

        [DataMember]
        public LinkedList<Edge> Edges { get; set; }

        [DataMember]
        public bool Marked { get; set; }

        [DataMember]
        public StationDTO Station { get; set; }

        

        public StationNode()
        {
            Edges = new LinkedList<Edge>();
        }

        public void AddEdge(Edge edge)
        {
            Edges.AddFirst(edge);
        }

        public void RemoveEdge(Edge edge)
        {
            Edges.Remove(edge);
        }

        public int CountEdges()
        {
            return Edges.Count;
        }

        public List<StationNode> GetAdjacencies()
        {
            List<StationNode> adjacencies = new List<StationNode>();
            foreach (Edge edge in Edges)
            {
                adjacencies.Add(edge.EndNode);
            }
            return adjacencies;
        }
        

        public bool RemoveEdgeTo(StationNode node)
        {
            foreach (Edge edge in Edges)
            {
                if (edge.EndNode == node)
                {
                    Edges.Remove(edge);
                    return true;
                }
            }
            return false;
        }
    }
}
